<?php
namespace jy_tour;
defined('BY_JYA') or exit('error');
/*
	门店
*/
class merch extends \plugin{
	public function order_verify($verify_code,$clerk_id){
		$order=$this->pdo_get('order',array('ordersn'=>$verify_code));
		if(!$order){
			exi('订单不存在！','error');
		}
		$order_verify=$this->pdo_get('order_verify',array('verify_code'=>$verify_code));
		if($order_verify['status'] || $order['status']==3){
			exi('核销码已被使用或已过期！','error');
		}
		if($order_verify['endtime'] && $order_verify['endtime']<TIMESTAMP){
			$this->pdo_update('order_verify',array('status'=>2),array('orderid'=>$order_verify['orderid']));
			exi('该核销码已过期！','error');
		}
		if(!$order_verify['id']){
			//按订单核销
			$order_verify=array(
				'uniacid'=>$_SESSION['uniacid'],
				'orderid'=>$order['id'],
				'createtime'=>TIMESTAMP,
				'status'=>1,
				'store_id'=>$this->order['storeid'],
				'verifytype'=>0,
				'verify_code'=>$verify_code,
			);
			$this->pdo_insert('order_verify',$order_verify);
		}elseif($order_verify['verifytype']==0){
			//按订单核销
			$update=array(
				'status'=>1,
				'clerk_id'=>$clerk_id,
				'verifytime'=>TIMESTAMP,
			);
			$this->pdo_update('order_verify',$update,array('id'=>$order_verify['id']));
		}
		$this->order_receive($order['id']);
		return true;
	}
	//确认收货，完成订单
	public function order_receive($order_id,$ismsg=false){
		$update=array('status'=>3,'finishtime'=>TIMESTAMP);
		$this->update('order',$update,array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
	}
}